<?php
namespace app\admin\controller;

use app\common\model\Category as CategoryModel;
use think\Controller;
use think\facade\Cache;

class Base extends Controller
{
    public function initialize()
    {
        $this->category = Cache::get('category');
        

        if (!$this->category) {
            $this->category = $this->setCategoryCache();
        }

        config([
            'USER_AUTH_KEY' => 'CloudWhaleAuthId',
            'SITE' => 'cloud-whale.com',
            'SITE_ACCESS' => 'cloud-whale.com',
        ], 'app');

        if (is_null(session('site'))) {
            session([
                'prefix' => config('app.SITE'),
                'type' => '',
                'expire' => 3600,
                'auto_start' => true,
            ]);

            session('site', config('app.SITE'));
        }
    }

    public function setCategoryCache()
    {
        $categoryList = CategoryModel::all();
        Cache::set('category', $categoryList);
        return $categoryList;
    }

    

}
